<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/**
 * @var \Magento\Shipping\Block\Adminhtml\View\Form $block
 */
$order = $block->getShipment()->getOrder();
?>
<?php echo $block->getChildHtml('order_info'); ?>
<section class="admin__page-section order-shipment-billing-shipping">
    <div class="admin__page-section-title">
        <span class="title"><?php echo $block->escapeHtml(__('Payment &amp; Shipping Method')); ?></span>
    </div>
    <div class="admin__page-section-content">

        <?php /* Billing Address */ ?>
        <div class="admin__page-section-item order-payment-method">
            <div class="admin__page-section-item-title">
                <span class="title"><?php echo $block->escapeHtml(__('Payment Information')); ?></span>
            </div>
            <div class="admin__page-section-item-content">
                <div><?php echo $block->getChildHtml('order_payment') ?></div>
                <div class="order-payment-currency">
                    <?php echo $block->escapeHtml(__('The order was placed using %1.', $order->getOrderCurrencyCode())); ?>
                </div>
            </div>
        </div>

        <?php /* Shipping Address */ ?>
        <div class="admin__page-section-item order-shipping-address">
            <div class="admin__page-section-item-title">
                <span class="title"><?php echo $block->escapeHtml(__('Shipping and Tracking Information')); ?></span>
            </div>
            <div class="admin__page-section-item-content">
                <div class="shipping-description-wrapper">
                    <?php if ($block->getShipment()->getTracksCollection()->count()): ?>
                        <p>
                            <a href="#" id="linkId"
                               onclick="popWin('<?php echo $block->escapeHtml($this->helper(Magento\Shipping\Helper\Data::class)->getTrackingPopupUrlBySalesModel($block->getShipment())); ?>','trackshipment','width=800,height=600,resizable=yes,scrollbars=yes')"
                               title="<?php echo $block->escapeHtml(__('Track this shipment')); ?>">
                                <?php echo $block->escapeHtml(__('Track this shipment')); ?>
                            </a>
                        </p>
                    <?php endif; ?>
                    <div class="shipping-description-title">
                        <?php echo $block->escapeHtml($order->getShippingDescription()) ?>
                    </div>

                    <?php echo $block->escapeHtml(__('Total Shipping Charges')); ?>:

                    <?php if ($this->helper(Magento\Tax\Helper\Data::class)->displayShippingPriceIncludingTax()): ?>
                        <?php $excl = $block->displayShippingPriceInclTax($order); ?>
                    <?php else: ?>
                        <?php $excl = $block->displayPriceAttribute('shipping_amount', false, ' '); ?>
                    <?php endif; ?>
                    <?php $incl = $block->displayShippingPriceInclTax($order); ?>

                    <?php /* @noEscape */ echo $excl; ?>
                    <?php if ($this->helper(Magento\Tax\Helper\Data::class)->displayShippingBothPrices() && $incl != $excl): ?>
                        (<?php echo $block->escapeHtml(__('Incl. Tax')); ?><?php /* @noEscape */ echo $incl; ?>)
                    <?php endif; ?>
                </div>

                <p>
                    <?php if ($block->canCreateShippingLabel()): ?>
                        <?php /* @noEscape */ echo $block->getCreateLabelButton() ?>
                    <?php endif ?>
                    <?php if ($block->getShipment()->getShippingLabel()): ?>
                        <?php /* @noEscape */ echo $block->getPrintLabelButton() ?>
                    <?php endif ?>
                    <?php if ($block->getShipment()->getPackages()): ?>
                        <?php /* @noEscape */ echo $block->getShowPackagesButton() ?>
                    <?php endif ?>
                </p>

                <?php echo $block->getChildHtml('shipment_tracking'); ?>
                <?php echo $block->getChildHtml('shipment_packaging'); ?>
                <script>
                    require([
                        'prototype'
                    ], function () {

                        setTimeout(function () {
                            packaging.setConfirmPackagingCallback(function () {
                                packaging.sendCreateLabelRequest();
                            });
                            packaging.setLabelCreatedCallback(function (response) {
                                setLocation("<?php echo $block->escapeUrl($block->getUrl(
                                    'adminhtml/order_shipment/view',
                                    ['shipment_id' => $block->getShipment()->getId()]
                                )); ?>");
                            });
                        }, 500);

                    });
                </script>
            </div>
        </div>
    </div>
</section>

<section class="admin__page-section">
    <div class="admin__page-section-title">
        <span class="title"><?php echo $block->escapeHtml(__('Items Shipped')); ?></span>
    </div>
    <?php echo $block->getChildHtml('shipment_items'); ?>
</section>

<section class="admin__page-section">
    <div class="admin__page-section-title">
        <span class="title"><?php echo $block->escapeHtml(__('Order Total')); ?></span>
    </div>
    <div class="admin__page-section-content">
        <?php echo $block->getChildHtml('shipment_packed'); ?>
        <div class="admin__page-section-item order-comments-history">
            <div class="admin__page-section-item-title">
                <span class="title"><?php echo $block->escapeHtml(__('Shipment History')); ?></span>
            </div>
            <div class="admin__page-section-item-content"><?php echo $block->getChildHtml('order_comments'); ?></div>
        </div>
    </div>
</section>
